package com.sale.controller;

import com.sale.entity.Book;
import com.sale.service.BookService;
import com.sale.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * Created by earl on 2018/5/8.
 */
@RestController
public class SaleController {

    @Autowired
    private BookService bookService;

    @Autowired
    private PayService payService;

    @GetMapping("/sale/{bookId}")
    public String sale(@PathVariable("bookId") Integer bookId) {
        System.out.println("销售模块处理销售");
        // 查找书本
        Book book = bookService.getBook(bookId);
        // 进行支付
        payService.doPay(new BigDecimal(10));
        return "销售成功，书名: " + book.getName() + ", 作者：" + book.getAuthor();
    }

    @GetMapping( "/hello")
    public String hell() {
        return "Hello";
    }

}
